const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');
const Device = require('./device');

const PrintJob = sequelize.define('PrintJob', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true
    },
    deviceId: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
            model: Device,
            key: 'id'
        }
    },
    fileName: {
        type: DataTypes.STRING,
        allowNull: false
    },
    fileSize: {
        type: DataTypes.INTEGER,
        allowNull: false
    },
    status: {
        type: DataTypes.ENUM('pending', 'printing', 'completed', 'failed'),
        defaultValue: 'pending'
    },
    startTime: {
        type: DataTypes.DATE
    },
    endTime: {
        type: DataTypes.DATE
    },
    errorMessage: {
        type: DataTypes.STRING
    }
});

// 设置关联关系
PrintJob.belongsTo(Device, { foreignKey: 'deviceId' });
Device.hasMany(PrintJob, { foreignKey: 'deviceId' });

module.exports = PrintJob; 